<% if params[:checkout].present? %>
  <%= turbo_frame_tag dom_id(@address) do %>
    <%= render 'spree/shared/error_messages', target: @address %>
    <%= form_for @address, html: { id: 'checkout_form_address' } do |f| %>
      <%= render 'spree/addresses/form',
        address_name: 'address',
        address_form: f,
        address_type: 'shipping',
        address: @address %>

      <%= hidden_field_tag :checkout, params[:checkout] %>
      <div class="flex justify-between items-center">
        <%= f.submit Spree.t(:update), class: 'btn btn-primary w-25 !py-2' %>
        <%= link_to Spree.t('actions.discard'), :back, class: 'btn btn-light w-25 !py-2' %>
      </div>
    <% end %>
  <% end %>
<% elsif turbo_frame_request? %>
  <%= turbo_frame_tag "edit_address_modal_#{@address.id}" do %>
    <%= render partial: 'spree/account/addresses/edit_address_modal', locals: { address: @address } %>
  <% end %>
<% else %>
  <div class="page-container grid grid-cols-1 lg:grid-cols-12 lg:gap-6 lg:mt-6">
    <div class="lg:col-span-2">
      <%= render 'spree/account/account_nav', current: 'address' %>
    </div>
    <div class="lg:col-span-6 lg:col-start-4">
      <div class="pb-4 border-b border-default -mx-4 lg:mx-0 px-4 lg:px-8">
        <h3 class="text-xl uppercase font-medium lg:font-semibold"><%= Spree.t(:edit_address) %></h3>
      </div>
      <%= render 'spree/shared/error_messages', target: @address %>
      <%= form_for @address, html: { id: 'checkout_form_address' }, method: :put do |f| %>
        <div class="lg:px-8 pt-4">
          <%= render 'spree/addresses/form',
            address_name: 'address',
            address_form: f,
            address_type: 'shipping',
            address: @address %>
        </div>
        <div class="lg:px-8 pb-4">
          <%= label_tag "default_shipping", class: "flex items-center gap-2 text-sm mb-4" do %>
            <%= check_box_tag "default_shipping", "true", @address.user_default_shipping?,
              class: 'input-checkbox input-address-default',
              disabled: @address.user_default_shipping? %>
            <%= Spree.t("address_book.set_as_default_delivery_address") %>
          <% end %>
          <%= label_tag "default_billing", class: "flex items-center gap-2 text-sm mb-4" do %>
            <%= check_box_tag "default_billing", "true", @address.user_default_billing?,
              class: 'input-checkbox input-address-default',
              disabled: @address.user_default_billing? %>
            <%= Spree.t("address_book.set_as_default_billing_address") %>
          <% end %>
        </div>
        <div class="border-t border-default -mx-4 lg:mx-0 px-4 flex justify-end items-center gap-4 py-6 lg:px-8">
          <%= link_to Spree.t('actions.cancel'), :back, class: 'uppercase text-sm font-semibold tracking-widest' %>
          <%= f.submit Spree.t(:update), class: 'btn-primary' %>
        </div>
      <% end %>
    </div>
  </div>
<% end %>
